package com.cnblogs.leizia.crm.workbench.web.controller;

import com.cnblogs.leizia.crm.commen.RequestUri;
import com.cnblogs.leizia.crm.commen.Result;
import com.cnblogs.leizia.crm.utils.PrintJson;
import com.cnblogs.leizia.crm.utils.ServiceFactory;
import com.cnblogs.leizia.crm.workbench.service.TranService;
import com.cnblogs.leizia.crm.workbench.service.impl.TranServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;

/**
 * 图表控制器
 *
 * @author leizi
 * @create 2021-05-10 20:51
 */
public class ChartController extends HttpServlet {

    TranService tranService = (TranService) ServiceFactory.getService(new TranServiceImpl());

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String path = req.getServletPath();

        if (RequestUri.CHART_GET_LIST.getUriPath().equals(path)) {
            getChartList(req, resp);
        }
    }

    /**
     * 获取交易统计图
     *
     * @param request
     * @param response
     * @return
     */
    private Result getChartList(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> map = tranService.getChartList();

        PrintJson.printJsonObj(response,Result.successToDataResult(map));

        return null;
    }
}
